<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
        <el-form-item label="供应商id(partnerId)" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入供应商id(partnerId)"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input
            v-model="queryParams.productName"
            placeholder="请输入产品名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <!-- <el-form-item label="Vendor Product Code" prop="productCode">
          <el-input
            v-model="queryParams.productCode"
            placeholder="请输入Vendor Product Code"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="Sequence" prop="sequence">
          <el-input
            v-model="queryParams.sequence"
            placeholder="请输入Sequence"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="最低采购数量" prop="minQty">
          <el-input
            v-model="queryParams.minQty"
            placeholder="请输入最低采购数量"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="供应商报价" prop="price">
          <el-input
            v-model="queryParams.price"
            placeholder="请输入供应商报价"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="Company" prop="companyId">
          <el-input
            v-model="queryParams.companyId"
            placeholder="请输入Company"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="Currency" prop="currencyId">
          <el-input
            v-model="queryParams.currencyId"
            placeholder="请输入Currency"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="Start Date" prop="dateStart">
          <el-date-picker clearable
            v-model="queryParams.dateStart"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择Start Date">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="End Date" prop="dateEnd">
          <el-date-picker clearable
            v-model="queryParams.dateEnd"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择End Date">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="Product Variant" prop="productId">
          <el-input
            v-model="queryParams.productId"
            placeholder="请输入Product Variant"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="Product Template" prop="productTmplId">
          <el-input
            v-model="queryParams.productTmplId"
            placeholder="请输入Product Template"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="Delivery Lead Time" prop="delay">
          <el-input
            v-model="queryParams.delay"
            placeholder="请输入Delivery Lead Time"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="Created by" prop="createUid">
          <el-input
            v-model="queryParams.createUid"
            placeholder="请输入Created by"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="Created on" prop="createDate">
          <el-date-picker clearable
            v-model="queryParams.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择Created on">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="Last Updated by" prop="writeUid">
          <el-input
            v-model="queryParams.writeUid"
            placeholder="请输入Last Updated by"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="Last Updated on" prop="writeDate">
          <el-date-picker clearable
            v-model="queryParams.writeDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择Last Updated on">
          </el-date-picker>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['system:supplierinfo:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:supplierinfo:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:supplierinfo:remove']"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:supplierinfo:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="supplierinfoList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <!-- <el-table-column label="id" align="center" prop="id" /> -->
        <el-table-column label="供应商id(partnerId)" align="center" prop="name" />
        <el-table-column label="产品名称" align="center" prop="productName" />
        <!-- <el-table-column label="Vendor Product Code" align="center" prop="productCode" /> -->
        <!-- <el-table-column label="Sequence" align="center" prop="sequence" /> -->
        <el-table-column label="最低采购数量" align="center" prop="minQty" />
        <el-table-column label="供应商报价" align="center" prop="price" />
        <!-- <el-table-column label="Company" align="center" prop="companyId" /> -->
        <!-- <el-table-column label="Currency" align="center" prop="currencyId" /> -->
        <!-- <el-table-column label="Start Date" align="center" prop="dateStart" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.dateStart, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="End Date" align="center" prop="dateEnd" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.dateEnd, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="Product Variant" align="center" prop="productId" /> -->
        <!-- <el-table-column label="Product Template" align="center" prop="productTmplId" /> -->
        <!-- <el-table-column label="Delivery Lead Time" align="center" prop="delay" /> -->
        <!-- <el-table-column label="Created by" align="center" prop="createUid" /> -->
        <!-- <el-table-column label="Created on" align="center" prop="createDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="Last Updated by" align="center" prop="writeUid" /> -->
        <!-- <el-table-column label="Last Updated on" align="center" prop="writeDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.writeDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column> -->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['system:supplierinfo:edit']"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:supplierinfo:remove']"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
      <!-- 添加或修改库存供应商信息对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="150px">
          <el-form-item label="供应商id(partnerId)" prop="name">
            <el-input v-model="form.name" placeholder="请输入供应商id(partnerId)" />
          </el-form-item>
          <el-form-item label="产品名称" prop="productName">
            <el-input v-model="form.productName" placeholder="请输入产品名称" />
          </el-form-item>
          <!-- <el-form-item label="Vendor Product Code" prop="productCode">
            <el-input v-model="form.productCode" placeholder="请输入Vendor Product Code" />
          </el-form-item>
          <el-form-item label="Sequence" prop="sequence">
            <el-input v-model="form.sequence" placeholder="请输入Sequence" />
          </el-form-item> -->
          <el-form-item label="最低采购数量" prop="minQty">
            <el-input v-model="form.minQty" placeholder="请输入最低采购数量" />
          </el-form-item>
          <el-form-item label="供应商报价" prop="price">
            <el-input v-model="form.price" placeholder="请输入供应商报价" />
          </el-form-item>
          <!-- <el-form-item label="Company" prop="companyId">
            <el-input v-model="form.companyId" placeholder="请输入Company" />
          </el-form-item>
          <el-form-item label="Currency" prop="currencyId">
            <el-input v-model="form.currencyId" placeholder="请输入Currency" />
          </el-form-item>
          <el-form-item label="Start Date" prop="dateStart">
            <el-date-picker clearable
              v-model="form.dateStart"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择Start Date">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="End Date" prop="dateEnd">
            <el-date-picker clearable
              v-model="form.dateEnd"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择End Date">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="Product Variant" prop="productId">
            <el-input v-model="form.productId" placeholder="请输入Product Variant" />
          </el-form-item>
          <el-form-item label="Product Template" prop="productTmplId">
            <el-input v-model="form.productTmplId" placeholder="请输入Product Template" />
          </el-form-item>
          <el-form-item label="Delivery Lead Time" prop="delay">
            <el-input v-model="form.delay" placeholder="请输入Delivery Lead Time" />
          </el-form-item>
          <el-form-item label="Created by" prop="createUid">
            <el-input v-model="form.createUid" placeholder="请输入Created by" />
          </el-form-item>
          <el-form-item label="Created on" prop="createDate">
            <el-date-picker clearable
              v-model="form.createDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择Created on">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="Last Updated by" prop="writeUid">
            <el-input v-model="form.writeUid" placeholder="请输入Last Updated by" />
          </el-form-item>
          <el-form-item label="Last Updated on" prop="writeDate">
            <el-date-picker clearable
              v-model="form.writeDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择Last Updated on">
            </el-date-picker>
          </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import { listSupplierinfo, getSupplierinfo, delSupplierinfo, addSupplierinfo, updateSupplierinfo } from "@/api/system/supplierinfo";
  
  export default {
    name: "Supplierinfo",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 库存供应商信息表格数据
        supplierinfoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          productName: null,
          productCode: null,
          sequence: null,
          minQty: null,
          price: null,
          companyId: null,
          currencyId: null,
          dateStart: null,
          dateEnd: null,
          productId: null,
          productTmplId: null,
          delay: null,
          createUid: null,
          createDate: null,
          writeUid: null,
          writeDate: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          name: [
            { required: true, message: "供应商id(partnerId)不能为空", trigger: "blur" }
          ],
          minQty: [
            { required: true, message: "最低采购数量不能为空", trigger: "blur" }
          ],
          price: [
            { required: true, message: "供应商报价不能为空", trigger: "blur" }
          ],
          currencyId: [
            { required: true, message: "Currency不能为空", trigger: "blur" }
          ],
          delay: [
            { required: true, message: "Delivery Lead Time不能为空", trigger: "blur" }
          ],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询库存供应商信息列表 */
      getList() {
        this.loading = true;
        listSupplierinfo(this.queryParams).then(response => {
          this.supplierinfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          name: null,
          productName: null,
          productCode: null,
          sequence: null,
          minQty: null,
          price: null,
          companyId: null,
          currencyId: null,
          dateStart: null,
          dateEnd: null,
          productId: null,
          productTmplId: null,
          delay: null,
          createUid: null,
          createDate: null,
          writeUid: null,
          writeDate: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加库存供应商信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getSupplierinfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改库存供应商信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateSupplierinfo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addSupplierinfo(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除库存供应商信息编号为"' + ids + '"的数据项？').then(function() {
          return delSupplierinfo(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/supplierinfo/export', {
          ...this.queryParams
        }, `supplierinfo_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  